<?php

include_once (_CORE_PATH . "lang/lang_instance.php");

class MozgLang
{
	private function __construct(){}
	
	static private $_langInstances = array();
	
	static public function _($text)
	{
		$params = array();
		if (func_num_args() > 1) 
		{
			$params = func_get_args();
			unset($params[0]);	
		}
		
		return self::Translate(self::GetLang(), $text, $params);
	}

	static public function _L($lang, $text)
	{
		$params = array();
		if (func_num_args() > 2) 
		{
			$params = func_get_args();
			unset($params[0]);
			unset($params[1]);	
		}		
		
		return self::Translate($lang, $text, $params);
	}	
	
	static private function Translate($lang, $text, $params)
	{
		return self::GetLangInstance($lang)->Translate($text, $params, self::IsDebugMode());
	}
	
	static private function GetLangInstance($lang)
	{
		if (!isset(self::$_langInstances[$lang]))
		{
			self::$_langInstances[$lang] = new lang_instance(_APP_PATH. 'language/' .$lang);
		} 

		return self::$_langInstances[$lang];
	}
	
	static public function Load($langPackName, $lang = false)
	{
		if (!$lang) $lang = self::GetLang();
		self::GetLangInstance($lang)->Load($langPackName);
	}	
	
	static private $_lang = false;
	
	static public function SetLang($lang)
	{
		if (!$lang) return;
		self::$_lang = $lang;
	}

	static public function GetLang()
	{
		if (!self::$_lang) self::$_lang = MozgCfg::GetProp('global//lang');
		return self::$_lang;
	}
	
	static private $_debugMode = null;
	
	static public function SetDebugMode($mode = true)
	{
		self::$_debugMode = (bool)$mode;
	}	
	
	static public function IsDebugMode()
	{
		if (is_null(self::$_debugMode)) self::$_debugMode = (bool)MozgCfg::GetProp('global//debugLang');
		return self::$_debugMode;
	}	
}